package com.sunchen.asc.service.user.repository;

import com.sunchen.asc.service.user.domain.Authentication;
import com.sunchen.asc.service.user.domain.Role;
import com.sunchen.asc.service.user.vo.AuthVo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface AuthenticationRepository extends JpaRepository<Authentication,Long> {

    Long countByName(String name);

    @Query(value = "select role_id from role_authentications where authentications_id = ?1",nativeQuery = true)
    List<Long> findRoles(Long id);

    Authentication findFirstByName(String name);

    @Query("select t.name from Authentication t where t.id = ?1")
    String findNameById(Long id);

    @Query("select new com.sunchen.asc.service.user.vo.AuthVo(t.id,t.name,t.title) from Authentication t ")
    List<AuthVo> findVo();

    Page<Authentication> findByTitleLike(Pageable pageable, String title);
}
